<?php
	session_start();
	if(!isset($_SESSION['username'])){
		header('Location: index.php');
	}
?>
<html>
<head>
<title>Tractors</title>
<style>
	#header{
		width: 99%:
		height: 10%;
	}
	#sidebar{
		width: 20%;
		height: 89%;
		float: left;
	}
	#container{
		width: 79%;
		height: 89%;
		float: left;
	}
	p{
		float: right;
	}
</style>
</head>
<body>
<div id = "header"><h2>Tractors</h2></div>
<div id = "sidebar"> 
	<a href = "add_tractor.php">Add tractor</a>
</div>
<div id = "container">
	<table border = 1>
	<?php
		$dbConnection = mysqli_connect('localhost', 'root', 'root', 'tractor');
		$query = "select producer_id, model, price from producer";
		$result = mysqli_query($dbConnection, $query);
		while($row = mysqli_fetch_assoc($result)){
			echo '<form action = "action_resolver.php" method = "post"><tr><td>
			       Producer id: <input readonly name = "producer_id" value = "'.$row["producer_id"].'"/>
				</td><td>Price: <input readonly name = "money" value = "'.$row["price"].'"/>
				</td><td>Model: <input readonly name = "model" value = "'.$row["model"].'"/>
				</td><td><img src = "http://img3.wikia.nocookie.net/__cb20100627043259/pixar/images/0/02/Tractor3.jpg" width = "50" height = "50"/> ';
			echo '</td><td><input type="submit" name="submit" value="Edit">
				  <input type="submit" name="submit" value="Delete">
				  <input type="submit" name="submit" value="Buy">';
			echo '</td></tr>	<br/></form>';
		}
	?>
	</table> 
	<p>
		<?php
			if(isset($_SESSION['message'])){
				echo $_SESSION['message'];
				$_SESSION['message'] = '';
			} 
		?>
	</p>
	<p>
		<?php 
			echo "Welcome ". $_SESSION['username'].", balance: ".$_SESSION['money'];
		?>
	</p>
</div>
</body>
</html>